package com.ruoyi.project.dict.dictsentence.service.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.TableSplitUtil;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.dict.dictsentence.domain.CiSentence;
import com.ruoyi.project.dict.dictsentence.mapper.CiSentenceMapper;
import com.ruoyi.project.dict.dictsentence.service.ICiSentenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 造句管理Service业务层处理
 *
 * @author shixiangwen
 * @date 2020-09-22
 */
@Service
@DataSource(DataSourceType.DICT)
public class CiSentenceServiceImpl implements ICiSentenceService {
    @Autowired
    private CiSentenceMapper ciSentenceMapper;

    /**
     * 查询造句管理
     *
     * @param ciSentence 造句管理ID
     * @return 造句管理
     */
    @Override
    public CiSentence selectCiSentenceById(CiSentence ciSentence) {
        return ciSentenceMapper.selectCiSentenceById(ciSentence);
    }

    /**
     * 查询造句管理列表
     *
     * @param ciSentence 造句管理
     * @return 造句管理
     */
    @Override
    public List<CiSentence> selectCiSentenceList(CiSentence ciSentence) {
        if (!StringUtils.isEmpty(ciSentence.getCi())) {
            String table = TableSplitUtil.getCiSentenceTable(ciSentence.getCi());
            ciSentence.setTable(table);
            return ciSentenceMapper.selectCiSentenceList(ciSentence);
        } else {
            return new ArrayList<>();
        }
    }

    /**
     * 新增造句管理
     *
     * @param ciSentence 造句管理
     * @return 结果
     */
    @Override
    public int insertCiSentence(CiSentence ciSentence) {
        String table = TableSplitUtil.getCiSentenceTable(ciSentence.getCi());
        ciSentence.setTable(table);
        return ciSentenceMapper.insertCiSentence(ciSentence);
    }

    /**
     * 修改造句管理
     *
     * @param ciSentence 造句管理
     * @return 结果
     */
    @Override
    public int updateCiSentence(CiSentence ciSentence) {
        String table = TableSplitUtil.getCiSentenceTable(ciSentence.getCi());
        ciSentence.setTable(table);
        return ciSentenceMapper.updateCiSentence(ciSentence);
    }

    /**
     * 删除造句管理信息
     *
     * @param ciSentence 造句管理ID
     * @return 结果
     */
    @Override
    public int deleteCiSentenceById(CiSentence ciSentence) {
        return ciSentenceMapper.deleteCiSentenceById(ciSentence);
    }
}
